from 点餐系统.工具类.untils import json_crud

# 会员列表
member_list = {'ddd': 'asd', 'adm': 'pwd'}

# 点餐表
din_list = []

# 餐桌号
desk_num = []

json_url = '../数据类/menu.json'

json_url2 = '../数据类/member_list.json'

json_crud = json_crud()

menu_list = json_crud.get_json_kv(json_url)

memberList = json_crud.get_json_kv(json_url2)


class canteen_methods:
    # 会员注册
    def member_add(self):
        while True:
            account = input("请输入会员账号\n")
            password = input("请输入会员密码\n")
            password2_par = input("请再次输入密码!\n")
            if not all([account, password, password2_par]):
                print("输入信息不完整！")
                continue
            if password == password2_par:
                # 将账号密码的键值对加入字典中
                member_list[account] = password
                break
            else:
                print("两次密码不一致，请检查！")
                continue

    # 会员登录验证
    def member_check(self):
        account = input("请输入会员账号\n")
        password = input("请输入会员密码\n")
        while True:
            if password == member_list.get(account, '未查询到账号！'):
                print('登陆成功，欢迎进入餐厅，{}!'.format(account))
                break
            else:
                print("密码错误，请重新输入账号密码！\n")
                account = input("请重新输入会员账号\n")
                password = input("请重新输入会员密码\n")

    # 进入餐厅
    def come_in_canteen(self):
        print('')

    # 根据点餐的结果输出订单
    @staticmethod
    def pull_list():
        if len(din_list) == 0:
            print('对不起，您啥也没买！')
        else:
            print('您的选购清单：')
            for i in range(len(din_list)):
                list_no = din_list[i][0]
                din_num = din_list[i][1]
                price = menu_list[list_no - 1]['价格']

                print(menu_list[list_no]['名称'] + '购买{}份~单价为：{}元，总计{}元'
                      .format(din_num, price, din_num * price))

    # 点餐
    @staticmethod
    def order_food():
        print('为您展示菜单！\n今日菜单如下：')
        for i in range(len(menu_list)):
            print('[ {} {}------{}元  ]'.format(i, menu_list[i]['名称'], menu_list[i]['价格']))
        ord_status = int(input('按任意键可以根据序号选择您所需的餐品，按0退出点餐\n'))
        if ord_status == 0:
            print("退出点餐")
        else:
            while True:
                stu = int(input("请输入餐品对应的序号\n"))
                while int(stu) > i or int(stu) < 0:
                    print("您输入的序号有误，请检查")
                    stu = int(input("请重新输入餐品对应的序号\n"))
                num = int(input("请输入购买的餐品数量\n"))
                din_list.append([stu, num])
                print("是否继续选购？（y/是，n/否）")
                con_k = input()
                if con_k == 'y':
                    continue
                else:
                    canteen_methods.pull_list()
                    break
